// components/orderGoodsList/orderGoodsList.js
const defaultStyle = {
    style: 1,
    //1——横向滚动列表+列表信息（无商品状态），2——竖向列表+列表信息（无商品状态），3——横向滚动列表+商品状态（有详细列表弹窗），4横向滚动列表+商品状态（无详细列表弹窗）
    mainColor: "#47B34F",
    screenFull: true,
    styleConfig: {
        backgroundColor: "#fff"
    }
};

Component({
    /**
   * 组件的属性列表
   */
    options: {
        addGlobalClass: true
    },
    properties: {
        goodsListStyle: {
            type: Object,
            observer(newVal, oldVal, changPath) {
                let that = this;
                var comStyle = this.data.comStyle;
                var listStyle = that.data.listStyle;
                that.setData({
                    leaderName: newVal.leaderName,
                    comStyle: {
                        ...comStyle,
                        ...newVal
                    },
                    listStyle: {
                        ...listStyle,
                        style: newVal.style ? newVal.style : that.data.comStyle.style
                    }
                });
            }
        },
        goodsListData: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    listData: newVal
                });
            }
        },
        refundData: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    refund: newVal
                });
            }
        },
        proMoney: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    promoney: newVal
                });
            }
        },
        refundProPrice: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    refundAll: newVal
                });
            }
        },
        transFreeBarrier: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    transFree: newVal
                });
            }
        },
        deliveryWay: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    delivery_way: newVal
                });
            }
        },
        deliveryCost: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    delivery_cost: newVal
                });
            }
        },
        url: {
            type: String,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    comUrl: newVal
                });
            }
        },
        noTransSwitch: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    transSwitch: newVal
                });
            }
        },
        platTransSwitch: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    platTransSwitch: newVal
                });
            }
        },
        pinkagePrice: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    pinkagePrice: newVal
                });
            }
        },
        pinkage: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    pinkage: newVal
                });
            }
        },
        is_seckill: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    is_seckill: newVal
                });
            }
        },
        onlyDealer: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    onlyDealer: newVal
                });
            }
        },
        features: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    features: newVal
                });
            }
        },
        vipStatus: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    vipStatus: newVal
                });
            }
        },
        delivery_type: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    delivery_type: newVal
                });
            }
        }
    },
    observers: {
        "transFree, pinkagePrice,promoney": function(transFree, pinkagePrice, promoney) {
            let that = this;
            var trans_difference = parseFloat((transFree * 100 - promoney * 100) / 100).toFixed(2);
            var pink_difference = parseFloat((pinkagePrice * 100 - promoney * 100) / 100).toFixed(2);
            that.setData({
                trans_difference: trans_difference,
                pink_difference: pink_difference
            });
        }
    },
    /**
   * 组件的初始数据
   */
    data: {
        isHidden: true,
        comStyle: {
            ...defaultStyle
        },
        listData: {
            totalNum: 1,
            deliveryWay: "",
            item: [ {
                id: "0",
                //商品id
                proId: 0,
                icon: "https://test-sqtgxt.hdewm.com/backend/web/uploads/Worldidc_156698046463.jpeg",
                //商品缩略图
                proName: "儿童超Q特技三轮",
                //商品名称
                spec: "重量:100g;",
                //规格
                refund_control: "1",
                //是否是满减商品
                spec_fund: 0,
                //
                price: "0.01",
                //商品单价
                num: "2",
                //数量
                status: "-1",
                //售后状态，-1——仅退款，-2—— 退货退款，-3退货换货
                order_status: "1",
                //订单状态,
                vip_price: 0,
                is_vip: 0,
                weight: "0"
            } ]
        },
        listStyle: {}
    },
    /**
   * 组件的方法列表
   */
    methods: {
        processData() {
            let that = this;
            let trans_difference = parseFloat((that.data.transFree * 100 - that.data.promoney * 100) / 100).toFixed(2);
            let pink_difference = parseFloat((that.data.pinkagePrice * 100 - that.data.promoney * 100) / 100).toFixed(2);
            that.setData({
                trans_difference: trans_difference,
                pink_difference: pink_difference
            });
        },
        goTo(e) {
            wx.navigateTo({
                url: e.currentTarget.dataset.url
            });
        },
        lookDetail(e) {
            var style = this.data.comStyle.style;
            if (style == 4) {
                if (e.currentTarget.dataset.url) {
                    wx.navigateTo({
                        url: e.currentTarget.dataset.url
                    });
                }
            } else {
                this.setData({
                    isHidden: false
                });
            }
            this.triggerEvent("myevent");
        },
        hiddenModal(e) {
            this.setData({
                isHidden: e.detail.goodsIsHidden
            });
        }
    },
    lifetimes: {
        ready() {
            let that = this;
            that.processData();
        }
    }
});